#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n;
    vector<string> queue;
    cin>>n;
    string action;
    string name;
    for(int i = 0; i<n; i++)
    {
        cin>>action;
        if(action == "in")
        {
            cin>>name;
            queue.push_back(name);       
        }
        if(action =="out")
        {
            queue.erase(queue.begin(), queue.begin()+1);
        }
        if(action == "q")
        {
            if(queue.size() == 0)
                cout<<"NULL"<<endl;
            else
                cout<<*queue.begin()<<endl;
        }
    }    
}